<?php

namespace Yz\modules\Generic;

class Template_Neighbors
    extends \Yz_Template_Native
{

    protected $itemName;
    protected $modelName = "Default";

    protected function doRender()
    {
        $v =& $this->value;
        if (array_key_exists('item', $v)) {
            $item = $v['item'];

            // fetch item's prev/next
            $model = $this->module->selectModel($this->modelName);
            if (null !== $this->itemName) {
                $item0 = $model->selectItem($this->itemName);
                $item0->id = $item->id;
                $item = $item0;
            }

            $v['prevItem'] = $model->fetchPreviousItem($item);
            $v['nextItem'] = $model->fetchNextItem($item);

        }
        return parent::doRender();
    }

}
